package com.xiaoma.tpo.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.BonusClassAchievementRecord;
import com.xiaoma.tpo.dto.BonusBoard;

@Repository
public class ClsAchievementBonusRecordDao extends BaseDaoImpl<BonusClassAchievementRecord>{

//    @SuppressWarnings("unchecked")
//    public List<BonusClassAchievementRecordVo> findAchievementBonusRecordVos(int userId) {
//        String sql = "select a.id, a.user_id, a.cls_class_id,a.bonus_point,a.created_at,b.title,b.img from bonus_class_achievement_record a left join bonus_class_achievement_resource b on a.resource_id = b.id where a.user_id = ?";
//        List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(BonusClassAchievementRecordVo.class, getNameHandler()),userId);
//        return (List<BonusClassAchievementRecordVo>)result;
//    }
    
    @SuppressWarnings("unchecked")
    public List<BonusBoard> findMaxAchievements(int userId) {
        String sql = "select user_id, sum(t.bonus_point) as bonus_point, title, img from (select a.user_id,a.bonus_point,b.title,b.img, a.cls_class_id from bonus_class_achievement_record a left join bonus_class_achievement_resource b on a.resource_id = b.id where a.user_id = ? order by a.achievement desc) t group by t.cls_class_id;";
        List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(BonusBoard.class, getNameHandler()),userId);
        return (List<BonusBoard>)result;
    }
}
